﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;

/// <summary>
/// Summary description for Others
/// </summary>
static public class Others
{
    static public IPAddress[] StringArrayToIPArray(string[] array)
    {
        if (array != null)
        {
            return array.Select(ip => IPAddress.Parse(ip)).ToArray();
        }
        else
        {
            return new IPAddress[0];
        }
    }

    static public string FormatSize(ulong size)
    {
        var u = "bytes";
        double d = size;
        if (d >= 1024)
        {
            d = d / 1024;
            u = "KB";

            if (d >= 1024)
            {
                d = d / 1024;
                u = "MB";

                if (d >= 1024)
                {
                    d = d / 1024;
                    u = "GB";

                    if (d >= 1024)
                    {
                        d = d / 1024;
                        u = "TB";
                    }
                }
            }
        }

        return string.Format("{0:0.00} {1}", d, u);
    }

    static public double CalculateProcentage(double value, double max)
    {
        return (value / max) * 100;
    }
}
